package com.back.common.api.vo;


import com.back.common.constant.CommonConstant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * 接口返回数据格式
 *
 * @author
 * @since 2025-02-07
 */

@Data
@ApiModel(value = "接口返回对象", description = "接口返回对象")
public class Result<T> implements Serializable {

    /**
     * 成功标识
     */
    @ApiModelProperty(value = "成功标识")
    private Boolean success = true;


    /**
     * 返回处理消息
     */
    @ApiModelProperty(value = "返回处理消息")
    private String message = "操作成功！";

    /**
     * 返回代码
     */
    @ApiModelProperty(value = "返回代码")
    private Integer code = 0;

    /**
     * 返回数据对象 data
     */
    @ApiModelProperty(value = "返回数据对象")
    private T result;

    /**
     * 时间戳
     */
    @ApiModelProperty(value = "时间戳")
    private long timestamp = System.currentTimeMillis();

    public Result() {}

    public static Result<Object> ok() {
        Result<Object> result = new Result<Object>();
        result.setSuccess(true);
        result.setCode(CommonConstant.SUCCESS);
        result.setMessage("成功");

        return result;
    }

    public static Result<Object> ok(String message) {
        Result<Object> result = new Result<Object>();
        result.setSuccess(true);
        result.setCode(CommonConstant.SUCCESS);
        result.setMessage(message);

        return result;
    }

    public static Result<Object> ok(Object data) {
        Result<Object> result = new Result<Object>();
        result.setSuccess(true);
        result.setCode(CommonConstant.SUCCESS);
        result.setResult(data);

        return result;
    }

    public static Result<Object> ok(String message, Object data) {
        Result<Object> result = new Result<Object>();
        result.setSuccess(true);
        result.setCode(CommonConstant.SUCCESS);
        result.setMessage(message);
        result.setResult(data);

        return result;
    }

    public static Result<Object> error500(String message) {
        Result<Object> result = new Result<Object>();
        result.setSuccess(false);
        result.setCode(CommonConstant.INTERNET_SERVER_ERROR_500);
        result.setMessage(message);

        return result;
    }
}
